<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="118px">
      <el-form-item label="订单号" prop="ddh">
        <el-input
          v-model="queryParams.ddh"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编码" prop="wlbm">
        <el-input
          v-model="queryParams.wlbm"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="wlmc">
        <el-input
          v-model="queryParams.wlmc"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下单日期">
        <el-date-picker
          v-model="daterangeXdrq"
          style="width: 209px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="交货日期">
        <el-date-picker
          v-model="daterangeJhrq"
          style="width: 209px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="客户名称" prop="khmc">
        <el-input
          v-model="queryParams.khmc"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单类型" prop="ddlx">
        <el-select v-model="queryParams.ddlx" placeholder="请选择订单类型" clearable>
          <el-option
            v-for="dict in dict.type.sys_ddlx"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="物料类型" prop="wllx">
        <el-select v-model="queryParams.wllx" placeholder="请选择物料类型" clearable>
          <el-option
            v-for="dict in dict.type.sys_wllx"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="计划审核状态" prop="jhshzt1">
        <el-select v-model="queryParams.jhshzt1" placeholder="请选择计划审核状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_shzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
     <!-- <el-form-item label="入库状态" prop="rkzt">
        <el-select v-model="queryParams.rkzt" placeholder="请选择入库状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_rkzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="入库时间" prop="rksj">
        <el-input
          v-model="queryParams.rksj"
          placeholder="请输入入库时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出库状态" prop="ckzt">
        <el-select v-model="queryParams.ckzt" placeholder="请选择出库状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_ckzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="出库时间" prop="cksj">
        <el-input
          v-model="queryParams.cksj"
          placeholder="请输入出库时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="订单状态" prop="ddzt">
        <el-select v-model="queryParams.ddzt" placeholder="请选择订单状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_ddzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->

      <!-- <el-form-item label="是否开票" prop="sfykp">
        <el-select v-model="queryParams.sfykp" placeholder="请选择是否已开发票" clearable>
          <el-option
            v-for="dict in dict.type.sys_yw_shifou"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:ddgl:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:ddgl:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['jhgl:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['jhgl:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['jhgl:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading"
    border
        	style="width: 130%"
        	:header-cell-style="{ fontSize: '13px', color: '#555',textAlign: 'center',background:'#E0E9F0' }"
        	:cell-style="{ textAlign: 'center' }"
    :data="ddglList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" fixed />
      <el-table-column label="订单号" align="center" prop="ddh" width="126" fixed />
      <el-table-column label="物料编码" align="center" prop="wlbm" width="136" fixed />
      <el-table-column label="物料名称" align="center" prop="wlmc" width="156" fixed />
      <el-table-column label="单位" align="center" prop="dw" width="55" />
      <el-table-column label="订单信息" >
        <el-table-column label="订单总量" align="center" prop="sl" width="75" />
        <el-table-column label="消库存量" align="center" prop="dhsXkcsl" width="75" />
        <el-table-column label="应新生产量" align="center" prop="dhsSjxzddsl" width="90" />
      </el-table-column>
      <el-table-column label="价格信息">
        <el-table-column label="单价" align="center" prop="ghsdj" width="75"/>
        <el-table-column label="订单总价" align="center" prop="ghszj" width="85">
            <template slot-scope="scope">
              <span>{{  scope.row.sl *  scope.row.ghsdj }}</span>
            </template>
        </el-table-column>
        <el-table-column label="供货商总价" align="center" prop="ghszj" width="95"/>
      </el-table-column>
      <el-table-column label="供应商" align="center" prop="deptName" width="130"/>
      <el-table-column label="下单日期" align="center" prop="xdrq" width="95">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.xdrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="交货日期" align="center" prop="jhrq" width="95">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jhrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="规格要求" align="center" prop="ggyq" width="156">
        <template slot-scope="scope">
        	<div v-if="scope.row.ggyq.length<50">{{scope.row.ggyq}}</div>
          <el-tooltip v-else placement="top" class="descTip">
          <div slot="content" v-html="scope.row.ggyq"></div>
        	<span class="singleLine">{{scope.row.ggyq}}</span>
        	</el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="工艺路线" align="center" prop="gylx" width="156">
        <template slot-scope="scope">
        	<div v-if="scope.row.gylx.length<19">{{scope.row.gylx}}</div>
          <el-tooltip v-else placement="top" class="descTip">
          <div slot="content" v-html="scope.row.gylx"></div>
        	<span class="singleLine">{{scope.row.gylx}}</span>
        	</el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="加工工序" align="center" prop="jjggx" width="95"/>
      <el-table-column label="重量" align="center" prop="zl" width="55"/>
      <el-table-column label="客户名称" align="center" prop="khmc" width="100"/>

      <!-- <el-table-column label="订单备注" align="center" prop="ddbz" width="150"/> -->
      <el-table-column label="订单类型" align="center" prop="ddlx" width="75">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_ddlx" :value="scope.row.ddlx"/>
        </template>
      </el-table-column>

      <!-- <el-table-column label="计划审核意见" align="center" prop="jhsh1shyj" width="75">
      </el-table-column>
      <el-table-column label="计划审核时间" align="center" prop="jhsh1gxsj" width="75">
      </el-table-column> -->
      <!-- <el-table-column label="外协订单ID,对于外协转自制的记录" align="center" prop="wxddid" /> -->
     <!-- <el-table-column label="供应商单价" align="center" prop="ghsdj" width="95"/>
      <el-table-column label="供应商总价" align="center" prop="ghszj" width="95"/>
      <el-table-column label="供货商价格备注" align="center" prop="ghsjgbz" width="115"/> -->
      <!-- <el-table-column label="供应商价格维护人" align="center" prop="ghsjgwhr" /> -->
     <!-- <el-table-column label="价格维护时间" align="center" prop="ghsjgwhsj" width="115"/>
      <el-table-column label="总部价格审核状态" align="center" prop="zbjgshzt1" width="135">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_shzt" :value="scope.row.zbjgshzt1"/>
        </template>
      </el-table-column>
      <el-table-column label="总部价格审核意见" align="center" prop="zbjgsh1shyj" width="135" />
      <el-table-column label="总部价格审核时间" align="center" prop="zbjgsh1shsj"  width="125"/> -->
      <el-table-column label="物料类型" align="center" prop="wllx"  width="75">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_wllx" :value="scope.row.wllx"/>
        </template>
      </el-table-column>
      <el-table-column label="计划审核状态" class="bgRed" align="center" prop="jhshzt1" width="125">
        <template slot-scope="scope" >
          <dict-tag :options="dict.type.sys_shzt"  :value="scope.row.jhshzt1"/>
        </template>
      </el-table-column>
     <!-- <el-table-column label="物料审核状态" align="center" prop="wlshzt1" width="115">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_shzt" :value="scope.row.wlshzt1"/>
        </template>
      </el-table-column>
      <el-table-column label="物料审核意见" align="center" prop="wlsh1shyj" width="125"/>
      <el-table-column label="物料审核时间" align="center" prop="wlsh1gxsj" width="115"/>
      <el-table-column label="入库状态" align="center" prop="rkzt" width="75">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_rkzt" :value="scope.row.rkzt"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="入库备注" align="center" prop="rkbz" /> -->
<!--      <el-table-column label="入库时间" align="center" prop="rksj" width="75"/> -->
      <!-- <el-table-column label="入库人" align="center" prop="rkr" /> -->
     <!-- <el-table-column label="出库状态" align="center" prop="ckzt" width="75">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_ckzt" :value="scope.row.ckzt"/>
        </template>
      </el-table-column>
      <el-table-column label="出库备注" align="center" prop="ckbz" width="125"/>
      <el-table-column label="出库时间" align="center" prop="cksj" width="75"/> -->
      <!-- <el-table-column label="出库人" align="center" prop="ckr" /> -->
      <!-- <el-table-column label="订单状态(总体状态),10待入库,11已入库,20待出库,21已出库" align="center" prop="ddzt">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_ddzt" :value="scope.row.ddzt"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="是否已开发票,0否1是" align="center" prop="sfykp">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yw_shifou" :value="scope.row.sfykp"/>
        </template>
      </el-table-column>
      <el-table-column label="发票ID" align="center" prop="fpid" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="125">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdateXq(scope.row)"
            v-hasPermi="['jhgl:detail']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['jhgl:edit']"
            :disabled="scope.row.jhshzt1=='1'||scope.row.jhshzt1=='0'"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-checked"
            @click="handleUpdateSh(scope.row)"
            v-hasPermi="['jhgl:shenhe']"
            :disabled="scope.row.jhshzt1=='1'||scope.row.jhshzt1=='0'"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['jhgl:remove']"
            :disabled="scope.row.jhshzt1=='1'||scope.row.jhshzt1=='0'"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改进销存_计划与订单管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="980px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
         <!--1，计划/订单信息 -->
        <el-form-item label="订单号" prop="ddh">
          <el-input v-model="form.ddh" placeholder="请输入订单号" :disabled="isJhshShow"/>
        </el-form-item>
        <el-form-item label="物料编码" prop="wlbm">
          <el-input v-model="form.wlbm" placeholder="请输入物料编码" :disabled="isJhshShow"/>
        </el-form-item>
        <el-form-item label="物料名称" prop="wlmc">
          <el-input v-model="form.wlmc" placeholder="请输入物料名称" :disabled="isJhshShow"/>
        </el-form-item>
        <el-form-item label="单位" prop="dw">
          <el-input v-model="form.dw" placeholder="请输入单位" :disabled="isJhshShow" />
        </el-form-item>
        <el-form-item label="数量" prop="sl">
          <el-input v-model="form.sl" placeholder="请输入数量" :disabled="isJhshShow" />
        </el-form-item>
        <el-form-item label="下单日期" prop="xdrq" :disabled="isJhshShow">
          <el-date-picker clearable
            v-model="form.xdrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择下单日期" :disabled="isJhshShow">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="交货日期" prop="jhrq">
          <el-date-picker clearable
            v-model="form.jhrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择交货日期" :disabled="isJhshShow">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="规格要求" prop="ggyq">
          <el-input v-model="form.ggyq" placeholder="请输入规格要求(下级零件,板厚,单件用量等)" :disabled="isJhshShow" />
        </el-form-item>
        <el-form-item label="工艺路线" prop="gylx">
          <el-input v-model="form.gylx" placeholder="请输入工艺路线" :disabled="isJhshShow" />
        </el-form-item>
        <el-form-item label="机加工工序" prop="jjggx">
          <el-input v-model="form.jjggx" placeholder="请输入机加工工序" :disabled="isJhshShow" />
        </el-form-item>
        <el-form-item label="重量" prop="zl">
          <el-input v-model="form.zl" placeholder="请输入重量" :disabled="isJhshShow" />
        </el-form-item>
        <el-form-item label="客户名称" prop="khmc" >
          <el-input v-model="form.khmc" placeholder="请输入客户名称" :disabled="isJhshShow" />
        </el-form-item>
       <el-form-item label="订货商机构代码" prop="dhsDeptId" style="display: none;">
          <el-input v-model="form.dhsDeptId" type="hidden" placeholder="请输入订货商机构代码,导入此订单的用户所属机构代码" />
        </el-form-item>
        <el-form-item label="供应商名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入供应商部门名称(从部门下拉选择)" :disabled="isJhshShow" />
        </el-form-item>
       <el-form-item label="供应商部门ID" prop="deptId" style="display: none;">
          <el-input type="hidden" v-model="form.deptId" placeholder="请输入供应商部门ID" :disabled="isJhshShow" />
        </el-form-item>

        <el-form-item label="订单类型" prop="ddlx">
          <el-select v-model="form.ddlx" placeholder="请选择订单类型" :disabled="isJhshShow">
            <el-option
              v-for="dict in dict.type.sys_ddlx"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物料类型" prop="wllx" >
          <el-select v-model="form.wllx" :disabled="isJhshShow" placeholder="请选择物料类型">
            <el-option
              v-for="dict in dict.type.sys_wllx"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="ddbz">
          <el-input type="textarea" v-model="form.ddbz" placeholder="请输入订单备注" :disabled="isJhshShow" />
        </el-form-item>
        <el-form-item label="计划审核结果" prop="jhshzt1"  v-show="isJhshShow">
           <el-radio-group v-model="form.jhshzt1">
             <el-radio :disabled="!isJhCanEditShow"
               v-for="dict in dict.type.sys_shzt"
               :key="dict.value"
               :label="dict.value"
             >{{dict.label}}</el-radio>
           </el-radio-group>
         </el-form-item>
         <el-form-item label="审核时间"    prop="jhsh1shsj" v-show="!isJhCanEditShow">
           <el-input  :disabled="!isJhCanEditShow" v-model="form.jhsh1gxsj" placeholder="请输入审核时间" />
         </el-form-item>
         <el-form-item label="审核意见"    prop="jhsh1shyj" v-show="isJhshShow">
           <el-input type="textarea" :disabled="!isJhCanEditShow" v-model="form.jhsh1shyj" placeholder="请输入审核意见" />
         </el-form-item>
        <!-- <el-form-item label="外协订单ID,对于外协转自制的记录" prop="wxddid">
          <el-input v-model="form.wxddid" placeholder="请输入外协订单ID,对于外协转自制的记录" />
        </el-form-item> -->
        <!-- 2，供应商维护价格信息 -->
        <!-- <el-form-item label="供应商单价" prop="ghsdj">
          <el-input v-model="form.ghsdj" placeholder="请输入供应商单价,由供应商维护" />
        </el-form-item>
        <el-form-item label="供应商总价" prop="ghszj">
          <el-input v-model="form.ghszj" placeholder="请输入供应商总价,系统自动计算" />
        </el-form-item>
        <el-form-item label="供货商价格备注" prop="ghsjgbz">
          <el-input v-model="form.ghsjgbz" placeholder="请输入供货商价格备注" />
        </el-form-item> -->
        <!-- <el-form-item label="供应商价格维护人" prop="ghsjgwhr">
          <el-input v-model="form.ghsjgwhr" placeholder="请输入供应商价格维护人" />
        </el-form-item>
        <el-form-item label="供货商价格维护时间" prop="ghsjgwhsj">
          <el-input v-model="form.ghsjgwhsj" placeholder="请输入供货商价格维护时间" />
        </el-form-item> -->
        <!-- 3，总部价格审核 -->
       <!-- <el-form-item label="总部价格审核状态" prop="zbjgshzt1">
          <el-radio-group v-model="form.zbjgshzt1">
            <el-radio
              v-for="dict in dict.type.sys_shzt"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="总部价格审核意见" prop="zbjgsh1shyj">
          <el-input v-model="form.zbjgsh1shyj" placeholder="请输入总部价格审核意见" />
        </el-form-item> -->
        <!-- <el-form-item label="总部价格审核时间" prop="zbjgsh1shsj">
          <el-input v-model="form.zbjgsh1shsj" placeholder="请输入总部价格审核时间" />
        </el-form-item> -->
         <!-- 4，补料审核 -->
        <!-- <el-form-item label="物料审核状态" prop="wlshzt1">
          <el-radio-group v-model="form.wlshzt1">
            <el-radio
              v-for="dict in dict.type.sys_shzt"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="物料审核更新时间" prop="wlsh1gxsj">
          <el-input v-model="form.wlsh1gxsj" placeholder="请输入物料审核更新时间" />
        </el-form-item> -->
        <!-- 5，入库出库操作 -->
        <!-- <el-form-item label="入库状态" prop="rkzt">
          <el-radio-group v-model="form.rkzt">
            <el-radio
              v-for="dict in dict.type.sys_rkzt"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="入库备注" prop="rkbz">
          <el-input v-model="form.rkbz" placeholder="请输入入库备注" />
        </el-form-item> -->
       <!-- <el-form-item label="入库时间" prop="rksj">
          <el-input v-model="form.rksj" placeholder="请输入入库时间" />
        </el-form-item>
        <el-form-item label="入库人" prop="rkr">
          <el-input v-model="form.rkr" placeholder="请输入入库人" />
        </el-form-item> -->
        <!-- <el-form-item label="出库状态" prop="ckzt">
          <el-radio-group v-model="form.ckzt">
            <el-radio
              v-for="dict in dict.type.sys_ckzt"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="出库备注" prop="ckbz">
          <el-input v-model="form.ckbz" placeholder="请输入出库备注" />
        </el-form-item> -->
        <!-- <el-form-item label="出库时间" prop="cksj">
          <el-input v-model="form.cksj" placeholder="请输入出库时间" />
        </el-form-item>
        <el-form-item label="出库人" prop="ckr">
          <el-input v-model="form.ckr" placeholder="请输入出库人" />
        </el-form-item> -->
        <!-- <el-form-item label="订单状态" prop="ddzt">
          <el-select v-model="form.ddzt" placeholder="请选择订单整体状态">
            <el-option
              v-for="dict in dict.type.sys_ddzt"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item> -->
       <!-- <el-form-item label="是否删除" prop="sfsc">
          <el-radio-group v-model="form.sfsc">
            <el-radio
              v-for="dict in dict.type.sys_yw_shifou"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <!-- <el-form-item label="是否已开发票" prop="sfykp">
          <el-radio-group v-model="form.sfykp">
            <el-radio
              v-for="dict in dict.type.sys_yw_shifou"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="发票ID" prop="fpid">
          <el-input v-model="form.fpid" placeholder="请输入发票ID" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="isJhCanEditShow && !isJhshShow">确 定</el-button>
        <el-button type="primary" @click="submitFormJhsh" v-show="isJhCanEditShow && isJhshShow">确定审核</el-button>
        <el-button @click="cancel" v-show="isJhCanEditShow">取 消</el-button>
        <el-button @click="cancel" v-show="!isJhCanEditShow">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 出入库导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" v-show="false"/><!-- 是否更新已经存在的业务数据 -->
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDdgl, getDdgl, delDdgl, addDdgl, updateDdgl,updateDdglJhsh,listJhgl } from "@/api/system/ddgl";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Ddgl",
  dicts: ['sys_ddzt', 'sys_shzt', 'sys_rkzt', 'sys_ckzt', 'sys_ddlx', 'sys_wllx', 'sys_yw_shifou'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 进销存_计划与订单管理表格数据
      ddglList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 计划审核显示的表单元素
      isJhshShow : false ,
      // 表单是否可编辑
      isJhCanEditShow: true ,
      // 发票ID时间范围
      daterangeXdrq: [],
      // 发票ID时间范围
      daterangeJhrq: [],

      // 导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/ddgl/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ddh: null,
        wlbm: null,
        wlmc: null,
        dw: null,
        sl: null,
        xdrq: null,
        jhrq: null,
        ggyq: null,
        gylx: null,
        jjggx: null,
        zl: null,
        khmc: null,
        dhsDeptId: null,
        deptName: null,
        deptId: null,
        ddbz: null,
        ddlx: null,
        jhshzt1: null,
        jhsh1shyj: null,
        jhsh1gxsj:null,
        jhshzt2: null,
        jhsh2shyj: null,
        jhsh2gxsj:null,
        wxddid: null,
        ghsdj: null,
        ghszj: null,
        ghsjgbz: null,
        ghsjgwhr: null,
        ghsjgwhsj: null,
        zbjgshzt1: null,
        zbjgsh1shyj: null,
        zbjgsh1shsj: null,
        zbjgshzt2: null,
        zbjgsh2shyj: null,
        zbjgsh2shsj: null,
        wllx: null,
        wlshzt1: null,
        wlsh1shyj: null,
        wlsh1gxsj: null,
        wlshzt2: null,
        wlsh2shyj: null,
        wlsh2gxsj: null,
        rkzt: null,
        rkbz: null,
        rksj: null,
        rkr: null,
        ckzt: null,
        ckbz: null,
        cksj: null,
        ckr: null,
        ddzt: null,
        createby: null,
        createtime: null,
        updateby: null,
        updatetime: null,
        sfsc: null,
        sfykp: null,
        rkfpid: null,
        ckfpid: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        ddh: [
          { required: true, message: "订单号不能为空", trigger: "blur" }
        ],
        createby: [
          { required: true, message: "录入人不能为空", trigger: "blur" }
        ],
        createtime: [
          { required: true, message: "录入时间不能为空", trigger: "blur" }
        ],
        updateby: [
          { required: true, message: "更新人不能为空", trigger: "blur" }
        ],
        updatetime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
        sfsc: [
          { required: true, message: "是否删除,0否1是不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询进销存_计划与订单管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeXdrq && '' != this.daterangeXdrq) {
        this.queryParams.params["beginXdrq"] = this.daterangeXdrq[0];
        this.queryParams.params["endXdrq"] = this.daterangeXdrq[1];
      }
      if (null != this.daterangeJhrq && '' != this.daterangeJhrq) {
        this.queryParams.params["beginJhrq"] = this.daterangeJhrq[0];
        this.queryParams.params["endJhrq"] = this.daterangeJhrq[1];
      }
      listJhgl(this.queryParams).then(response => {
        this.ddglList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ddid: null,
        ddh: null,
        wlbm: null,
        wlmc: null,
        dw: null,
        sl: null,
        xdrq: null,
        jhrq: null,
        ggyq: null,
        gylx: null,
        jjggx: null,
        zl: null,
        khmc: null,
        dhsDeptId: null,
        deptName: null,
        deptId: null,
        ddbz: null,
        ddlx: null,
        jhshzt1: null,
        jhsh1shyj: null,
        jhsh1gxsj:null,
        jhshzt2: null,
        jhsh2shyj: null,
        jhsh2gxsj:null,
        wxddid: null,
        ghsdj: null,
        ghszj: null,
        ghsjgbz: null,
        ghsjgwhr: null,
        ghsjgwhsj: null,
        zbjgshzt1: null,
        zbjgsh1shyj: null,
        zbjgsh1shsj: null,
        zbjgshzt2: null,
        zbjgsh2shyj: null,
        zbjgsh2shsj: null,
        wllx: null,
        wlshzt1: null,
        wlsh1shyj: null,
        wlsh1gxsj: null,
        wlshzt2: null,
        wlsh2shyj: null,
        wlsh2gxsj: null,
        rkzt: null,
        rkbz: null,
        rksj: null,
        rkr: null,
        ckzt: null,
        ckbz: null,
        cksj: null,
        ckr: null,
        ddzt: null,
        createby: null,
        createtime: null,
        updateby: null,
        updatetime: null,
        sfsc: null,
        sfykp: null,
        rkfpid: null,
        ckfpid: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeXdrq = [];
      this.daterangeJhrq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.ddid)
      //this.ids = selection.map(item => item.ddid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isJhshShow = false; //非计划审核展示，disabled=false表单可编辑
      this.title = "添加计划信息";
    },
    /** 详情按钮操作 */
    handleUpdateXq(row) {
      this.reset();
      const ddid = row.ddid || this.ids
      getDdgl(ddid).then(response => {
        this.form = response.data;
        this.open = true;
        this.isJhshShow = true;//disabled=true表单不可编辑
        this.isJhCanEditShow = false;//表单是否可编辑
        this.title = "计划详情";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ddid = row.ddid || this.ids
      getDdgl(ddid).then(response => {
        this.form = response.data;
        this.open = true;
        this.isJhshShow = false;//disabled=false表单可编辑
        this.isJhCanEditShow = true;//表单是否可编辑
        this.title = "计划修改";
      });
    },
    /** 审核按钮操作 */
    handleUpdateSh(row) {
      this.reset();
      const ddid = row.ddid || this.ids
      getDdgl(ddid).then(response => {
        this.form = response.data;
        this.form.jhshzt1 ="1"; //默认审核状态强制为"通过"
        this.open = true;
        this.isJhshShow = true;
        this.isJhCanEditShow = true;//表单是否可编辑
        this.title = "计划审核";
      });
    },
    /** 提交按钮（新增、修改） */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ddid != null) {
            updateDdgl(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDdgl(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮（计划审核） */
    submitFormJhsh() {
      // 验证审核状态的值是否合法
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ddid != null) {
            if(this.form.jhshzt1!='1' && this.form.jhshzt1!='0' ){
              this.$message({
                message: '请选择“通过”或“不通过”完成审批哦~',
                type: 'warning'
              });
              return ;
            }
            updateDdglJhsh(this.form).then(response => {
              this.$modal.msgSuccess("计划审核成功");
              this.open = false;
              this.getList();
            });
          } else {
              this.$modal.msgSuccess("数据ddid不合法,请刷新页面或重新登录后重试!");
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ddids = row.ddid || this.ids;
      this.$modal.confirm('是否确认删除所选计划信息？').then(function() {
        return delDdgl(ddids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ddgl/export', {
        ...this.queryParams
      }, `订单管理_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "计划导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('ddgl/importTemplate', {
      }, `订单导入_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
<style scoped>
@import "../../assets/styles/index.css";
::v-deep .el-popper .popper__arrow::after,
::v-deep .el-popper .popper__arrow {
	display: none;
}
::v-deep .el-upload-list {
	/* display: none; */
}
.el-icon-circle-close {
	font-size: 16px;
	color: #e65e5e;
	cursor: pointer;
	position: relative;
	top: 2px;
	left: 5px;
}
.bgRed{
  background-color: #e65e5e;
}
</style>
